import requests
import json
import pprint
import time

if __name__ == "__main__":
    videoId = 45382106
    r = requests.get(
        'https://api.bilibili.com/x/v2/reply?jsonp=jsonp&pn={}&type=1&oid={}&sort=0&_=1557291922647'.format(1,
                                                                                                            videoId))
    data_json = json.loads(r.text)
    # 获取总页数
    total_page = data_json['data']['page']['count']

    userMap = {}
    for page in range(1, total_page + 1):
        r = requests.get(
            'https://api.bilibili.com/x/v2/reply?jsonp=jsonp&pn={}&type=1&oid={}&sort=0&_=1557291922647'.format(page,
                                                                                                                videoId))
        data = json.loads(r.text)
        for i in data['data']['replies']:
            if i['member']['vip']['vipDueDate'] != 0:
                i['member']['vip']['vipDueDate'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(
                    i['member']['vip']['vipDueDate'] / 1000))
            userMap['id:' + i['member']['mid']] = 'name: ' + i['member']['uname'] + '  level: ' + str(
                i['member']['level_info']['current_level']) + ' vipTime: ' + str(i['member']['vip']['vipDueDate'])
    pprint.pprint(userMap)
